package poli.tidia.mobile;

import poli.tidia.mobile.proxy.LoginProxy;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;



public class LoginActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button btnSubmitLogin = (Button)findViewById(R.id.btnSubmitLogin);  
        btnSubmitLogin.setOnClickListener(LoginListener);  
    }
    
    private Button.OnClickListener LoginListener = new Button.OnClickListener() {  
		@Override
		public void onClick(View v) {
			EditText txtLogin = (EditText)findViewById(R.id.txtLogin);  
            EditText txtPassword = (EditText)findViewById(R.id.txtPassword);

            TextView output = (TextView) findViewById(R.id.outputView);
            LoginProxy l = new LoginProxy();
            String login = txtLogin.getText().toString();
            String Password = txtPassword.getText().toString();
            
            Boolean loginResult = l.doLogin(login, Password);
            if(loginResult)
            {
            	Intent menuIntent = new Intent(LoginActivity.this, SitesMenuActivity.class);
            	startActivity(menuIntent);
            }
            else
            {
            	output.append("Login falhou");
            }
		}  
   };  
}